home *** CD-ROM | disk | FTP | other *** search
- unit Main;
- {==================================================================}
- { Description: Getting Started Sample Application }
- { Copyright: ⌐ Copyright 1995-1999 Xceed Software Inc. }
- { All Rights Reserved. }
- {==================================================================}
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- OleCtrls, XceedZipLib_TLB, ComCtrls, StdCtrls, checklst;
-
- const
- { Property hints }
- cBasePathHint = 'BasePath property:' + #13#10 +
- ' This path determines where entries in the FilesToProcess and FilesToExclude' + #13#10 +
- ' properties are relative to. The base path never appears in the zip file, even if' + #13#10 +
- ' PreservePaths = True. Only the portion of the path and filename specified in' + #13#10 +
- ' the FilesToProcess property is actually stored in the zip file. Therefore,' + #13#10 +
- ' BasePath helps you control what portions of paths are stored in the zip file.' + #13#10 +
- ' (The BasePath property is irrelevant when you are using absolute paths)';
-
- cFilesToProcessHint = 'FilesToProcess property:' + #13#10 +
- ' Multiline string that contains all the filenames and/or file masks to be' + #13#10 +
- ' processed (zipped, unzipped, etc). If you entered a path in the' + #13#10 +
- ' BasePath property, all entries with relative paths will be relative to' + #13#10 +
- ' the specified base path. The pipe character can be used instead of' + #13#10 +
- ' the linefeed to separate entries for the FilesToProcess property.';
-
- cFilesToExcludeHint = 'FilesToExclude property:' + #13#10 +
- ' Multiline string that contains all filenames and/or file masks to exclude' + #13#10 +
- ' from the files to be processed by the FilesToProcess property. These' + #13#10 +
- ' entries are also relative to the path specified in the BasePath property' + #13#10 +
- ' if its not empty.';
-
- cProcessSubfoldersHint = 'ProcessSubfolders property:' + #13#10 +
- ' If set to True, the contents of all encoutered subfolders will be processed.';
-
- cZipFilenameHint = 'ZipFilename property:' + #13#10 +
- ' The filename of the zip file to work with. When unzipping, this file must' + #13#10 +
- ' exist. When zipping, if the file exists, it''s updated. Otherwise, it is' + #13#10 +
- ' created. You must enter an absolute path for this property. The' + #13#10 +
- ' BasePath property does not interfere with the ZipFilename property.';
-
- cPreservePathsHint = 'PreservePaths property:' + #13#10 +
- ' If set to True, the zip file will store both the path and the filename of' + #13#10 +
- ' each file that is being zipped. As usual, the portion of a file''s path' + #13#10 +
- ' that is specified in the BasePath property will not be stored in the' + #13#10 +
- ' zip file. When PreservePaths is set to False, only filenames (no' + #13#10 +
- ' paths) are stored.';
-
- cUseTempFileHint = 'UseTempFile property:' + #13#10 +
- ' If set to true, all zipping operations will be performed on a temp file' + #13#10 +
- ' located in the folder specified in the TempFolder property.' + #13#10 +
- ' Otherwise, the operation is performed directly on the zip file' + #13#10 +
- ' without using a temp file. You cannot remove files from an existing' + #13#10 +
- ' zip file, or update files already in an existing zip files without setting' + #13#10 +
- ' this property to True.';
-
- cTempFolderHint = 'TempFolder property:' + #13#10 +
- ' Location of the temp file when the UseTempFile property is set to True.' + #13#10 +
- ' When you leave this property empty, the Windows default temp' + #13#10 +
- ' directory is used.';
-
- cRequiredFileAttributesHint = 'RequiredFileAttributes property:' + #13#10 +
- ' Bit-field value that specifies all attributes that a file must have in' + #13#10 +
- ' order to be included in the process.';
-
- cExcludedFileAttributesHint = 'ExcludedFileAttributes property:' + #13#10 +
- ' Bit-field value that specifies all attributes that a file must NOT have' + #13#10 +
- ' in order to be included in the process.';
-
- cMinDateToProcessHint = 'MinDateToProcess property:' + #13#10 +
- ' Minimum value of a file''s ''Last modifed date'' required in order to be' + #13#10 +
- ' included in the process.';
-
- cMaxDateToProcessHint = 'MaxDateToProcess property:' + #13#10 +
- ' Maximum value of a file''s ''Last modifed date'' required in order to be' + #13#10 +
- ' included in the process.';
-
- cMinSizeToProcessHint = 'MinSizeToProcess property:' + #13#10 +
- ' Minimum file size that a file must have in order to be included in the process.';
-
- cMaxSizeToProcessHint = 'MaxSizeToProcess property:' + #13#10 +
- ' Maximum file size that a file must have in order to be included in the process.';
-
- cUnzipToFolderHint = 'UnzipToFolder property:' + #13#10 +
- ' Destination folder for files being unzipped. In this sample, the PreservePaths' + #13#10 +
- ' property is set to True, so if files are stored in the zip file with paths, those' + #13#10 +
- ' stored paths will be recreated inside the destination folder specified by the' + #13#10 +
- ' UnzipToFolder property.';
-
- cSkipIfExistingHint = 'SkipIfExisting property:' + #13#10 +
- ' If the destination file (located in a zip file that is being updated, or' + #13#10 +
- ' on disk when a zip file is being unzipped) already exists, and this' + #13#10 +
- ' property is set to True, then the file won''t be overwritten. This has' + #13#10 +
- ' the effect of only processing files that don''t exist in the destination' + #13#10 +
- ' zip file or unzipping folder.';
-
- cSkipIfNotExistingHint = 'SkipIfNotExisting property:' + #13#10 +
- ' Setting this property to True will cause only files that don''t already' + #13#10 +
- ' exist in the destination unzipping location (when unzipping) or the' + #13#10 +
- ' zip file (when zipping) to be skipped.';
-
- cSkipIfOlderDateHint = 'SkipIfOlderDate property:' + #13#10 +
- ' When updating a file (in a zip while zipping, or on disk while unzipping),' + #13#10 +
- ' the file is skipped if the existing file''s ''Last modified date'' is greater than' + #13#10 +
- ' the file being zipped or unzipped.';
-
- cSkipIfOlderVersionHint = 'SkipIfOlderVersion property:' + #13#10 +
- ' When updating a file (in a zip while zipping, or on disk while unzipping),' + #13#10 +
- ' the file is skipped if the existing file''s version resource value is greater' + #13#10 +
- ' than the file being zipped or unzipped.';
-
- cZipFilenameSfxHint = 'ZipFilename property with Sfx:' + #13#10 +
- ' The filename of the zip file to work on. When creating or updating' + #13#10 +
- ' self-extracting zip files, you should enter an executable filename' + #13#10 +
- ' (use a .EXE extension).';
-
- cSfxBinaryModuleHint = 'SfxBinaryModule property:' + #13#10 +
- ' This binary file will be prepended to the zip file, with configuration' + #13#10 +
- ' data if the binary is one of the Xceed Self-Extractor Module' + #13#10 +
- ' binaries. If you leave this field empty, a regular (non-sfx) zip file' + #13#10 +
- ' will be created.';
-
- cSfxStringsHint = 'SfxStrings property array:' + #13#10 +
- ' This array contains all the strings displayed by the Xceed Self-Extractor' + #13#10 +
- ' Module binaries. For example, the ''xssTitle'' index contains the title' + #13#10 +
- ' displayed by all dialog boxes.';
-
- cSfxMessagesHint = 'SfxMessages property array:' + #13#10 +
- ' This array contains all messages displayed by the Xceed Self-Extractor Module' + #13#10 +
- ' binaries. These messages often appear in their own dialog boxes. If a particular' + #13#10 +
- ' message is left empty, the dialog box won''t be displayed. As an example,' + #13#10 +
- ' leaving this field empty will avoid displaying an introduction message dialog.';
-
- { Method hints }
- cPreviewFilesHint = 'PreviewFiles method:' + #13#10 +
- ' Lets you scan the disk for files that would be zipped with the current property' + #13#10 +
- ' settings. A PreviewingFile event is triggered for each file that matches an' + #13#10 +
- ' entry in the FilesToProcess property. Set this method''s parameter to True to' + #13#10 +
- ' have the library calculate the compressed size of the previewed files.';
-
- cListZipContentsHint = 'ListZipContents method:' + #13#10 +
- ' Lets you view the zip file''s contents. Due to the fact that the FilesToProcess' + #13#10 +
- ' property and the other filtering properties affect the ListZipContents method,' + #13#10 +
- ' you can use it to preview which files would be unzipped by the Unzip method' + #13#10 +
- ' if it were called with the current property settings. A ListingFile event is' + #13#10 +
- ' triggered for each file in the zip file that is listed.';
-
- cZipHint = 'Zip method:' + #13#10 +
- ' Lets you zip files. Only files that match all the entries in the FilesToProcess' + #13#10 +
- ' and filtering properties will be processed. For each file that matches the' + #13#10 +
- ' FilesToProcess property, the ZipPreprocessingFile event is triggered. That' + #13#10 +
- ' event provides you with the chance to change the inclusion state of a file,' + #13#10 +
- ' or to change its information before it is stored in the zip file.';
-
- cUnzipHint = 'Unzip method:' + #13#10 +
- ' Lets you unzip files. Only files that match all the entries in the FilesToProcess' + #13#10 +
- ' and filtering properties will be processed. For each file that matches the' + #13#10 +
- ' FilesToProcess property, the UnzipPreprocessingFile event is triggered. That' + #13#10 +
- ' event provides you with the chance to change the inclusion state of a file, or' + #13#10 +
- ' to change its information before it is written to the destination unzipping folder.';
-
- cZipSfxHint = 'Zip method with Sfx:' + #13#10 +
- ' It''s just like creating a regular (non-sfx) zip file, but if you enter a value' + #13#10 +
- ' for the SfxBinaryModule property, the binary (or any file for that matter)' + #13#10 +
- ' is prepended to the zip file. The zip file is now self-extracting because' + #13#10 +
- ' the binary knows how to unzip the rest of the data after itself.' + #13#10 +
- ' Furthermore, if the library recognises an Xceed binary, it will add' + #13#10 +
- ' config data to the binary so that the self-extracting zip file can display' + #13#10 +
- ' intro messages and have custom behavior.';
-
- type
- TfrmMain = class(TForm)
- Label1: TLabel;
- shtPreview: TTabSheet;
- shtZip: TTabSheet;
- shtList: TTabSheet;
- shtUnzip: TTabSheet;
- shtSFX: TTabSheet;
- tabExamples: TPageControl;
- Label3: TLabel;
- edtPFilesToProcess: TMemo;
- Label4: TLabel;
- edtPFilesToExclude: TMemo;
- Label5: TLabel;
- lstPRequiredFileAttributes: TCheckListBox;
- lstPExcludedFileAttributes: TCheckListBox;
- Label6: TLabel;
- chkPProcessSubfolders: TCheckBox;
- btPreviewFiles: TButton;
- StatusBar1: TStatusBar;
- Label7: TLabel;
- edtResults: TMemo;
- Label8: TLabel;
- Label9: TLabel;
- edtZZipFilename: TEdit;
- Label10: TLabel;
- edtZBasePath: TEdit;
- Label11: TLabel;
- edtZFilesToProcess: TMemo;
- Label12: TLabel;
- edtZFilesToExclude: TMemo;
- chkZPreservePaths: TCheckBox;
- chkZProcessSubfolders: TCheckBox;
- chkZUseTempFile: TCheckBox;
- Label13: TLabel;
- edtZTempFolder: TEdit;
- btZip: TButton;
- Label14: TLabel;
- Label15: TLabel;
- Label16: TLabel;
- Label17: TLabel;
- edtLZipFilename: TEdit;
- Label18: TLabel;
- Label19: TLabel;
- Label20: TLabel;
- edtLMinSizeToProcess: TEdit;
- Label21: TLabel;
- edtLMaxSizeToProcess: TEdit;
- btList: TButton;
- dtLMinDateToProcess: TDateTimePicker;
- dtLMaxDateToProcess: TDateTimePicker;
- Label23: TLabel;
- edtUZipFilename: TEdit;
- Label24: TLabel;
- edtUUnzipToFolder: TEdit;
- Label25: TLabel;
- edtUFilesToProcess: TMemo;
- Label26: TLabel;
- edtUFilesToExclude: TMemo;
- chkUSkipIfExisting: TCheckBox;
- chkUSkipIfNotExisting: TCheckBox;
- chkUSkipIfOlderDate: TCheckBox;
- chkUSkipIfOlderVersion: TCheckBox;
- btUnzip: TButton;
- Label29: TLabel;
- edtSZipFilename: TEdit;
- Label30: TLabel;
- edtSFilesToProcess: TMemo;
- Label31: TLabel;
- edtSSfxBinaryModule: TEdit;
- Label32: TLabel;
- edtSTitle: TEdit;
- btZipSfx: TButton;
- Label33: TLabel;
- edtSIntro: TMemo;
- barFile: TProgressBar;
- barGlobal: TProgressBar;
- xZip: TXceedZip;
- Memo1: TMemo;
- Memo2: TMemo;
- Memo3: TMemo;
- procedure FormCreate(Sender: TObject);
- procedure btPreviewFilesClick(Sender: TObject);
- procedure btZipClick(Sender: TObject);
- procedure btListClick(Sender: TObject);
- procedure btUnzipClick(Sender: TObject);
- procedure btZipSfxClick(Sender: TObject);
- procedure xZipInsertDisk(Sender: TObject; nDiskNumber: Integer;
- var bDiskInserted: WordBool);
- procedure xZipWarning(Sender: TObject; const sFilename: WideString;
- xWarning: TOleEnum);
- procedure xZipListingFile(Sender: TObject; const sFilename,
- sComment: WideString; lSize, lCompressedSize: Integer;
- nCompressionRatio: Smallint; xAttributes: TOleEnum; lCRC: Integer;
- dtLastModified, dtLastAccessed, dtCreated: TDateTime;
- xMethod: TOleEnum; bEncrypted: WordBool; lDiskNumber: Integer;
- bExcluded: WordBool; xReason: TOleEnum);
- procedure xZipPreviewingFile(Sender: TObject; const sFilename,
- sSourceFilename: WideString; lSize: Integer; xAttributes: TOleEnum;
- dtLastModified, dtLastAccessed, dtCreated: TDateTime;
- bExcluded: WordBool; xReason: TOleEnum);
- procedure xZipSkippingFile(Sender: TObject; const sFilename, sComment,
- sFilenameOnDisk: WideString; lSize, lCompressedSize: Integer;
- xAttributes: TOleEnum; lCRC: Integer; dtLastModified, dtLastAccessed,
- dtCreated: TDateTime; xMethod: TOleEnum; bEncrypted: WordBool;
- xReason: TOleEnum);
- procedure xZipFileStatus(Sender: TObject; const sFilename: WideString;
- lSize, lCompressedSize, lBytesProcessed: Integer; nBytesPercent,
- nCompressionRatio: Smallint; bFileCompleted: WordBool);
- procedure xZipGlobalStatus(Sender: TObject; lFilesTotal,
- lFilesProcessed, lFilesSkipped: Integer; nFilesPercent: Smallint;
- lBytesTotal, lBytesProcessed, lBytesSkipped: Integer;
- nBytesPercent: Smallint; lBytesOutput: Integer;
- nCompressionRatio: Smallint);
- procedure xZipProcessCompleted(Sender: TObject; lFilesTotal,
- lFilesProcessed, lFilesSkipped, lBytesTotal, lBytesProcessed,
- lBytesSkipped, lBytesOutput: Integer; nCompressionRatio: Smallint;
- xResult: TOleEnum);
- procedure xZipReplacingFile(Sender: TObject; const sFilename,
- sComment: WideString; lSize: Integer; xAttributes: TOleEnum;
- dtLastModified, dtLastAccessed, dtCreated: TDateTime;
- const sOrigFilename: WideString; lOrigSize: Integer;
- xOrigAttributes: TOleEnum; dtOrigLastModified, dtOrigLastAccessed,
- dtOrigCreated: TDateTime; var bReplaceFile: WordBool);
- procedure xZipZipContentsStatus(Sender: TObject; lFilesRead,
- lFilesTotal: Integer; nFilesPercent: Smallint);
- private
- { Private declarations }
- procedure UpdateFieldHints;
- public
- { Public declarations }
- end;
-
- { Some useful global functions and procedures }
- procedure XceedResetDefaultProperties( var xZip : TXceedZip );
- procedure XceedFillAttributeList( var lstAttributes : TCheckListBox );
- function XceedGetSelectedAttributes( var lstAttributes : TCheckListBox ) : integer;
- procedure XceedSetSelectedAttributes( var lstAttributes : TCheckListBox; xAttrib : xcdFileAttributes );
-
- var
- frmMain: TfrmMain;
-
- implementation
-
- {$R *.DFM}
-
- {-----------------------------------------------------------------------------}
- { Some useful global functions and procedures }
- {-----------------------------------------------------------------------------}
-
- { Reset XceedZip properties }
- procedure XceedResetDefaultProperties( var xZip : TXceedZip );
- begin
- xZip.BasePath := '';
- xZip.CompressionLevel := xclHigh;
- xZip.EncryptionPassword := '';
- xZip.RequiredFileAttributes := xfaNone;
- xZip.ExcludedFileAttributes := xfaNone;
- xZip.FilesToProcess := '';
- xZip.FilesToExclude := '';
- xZip.MinDateToProcess := EncodeDate( 1900, 01, 01 );
- xZip.MaxDateToProcess := EncodeDate( 9999, 12, 31 );
- xZip.MinSizeToProcess := 0;
- xZip.MaxSizeToProcess := 0; { Zero means no upper limit }
- xZip.SplitSize := 0; { Zero means no split }
- xZip.PreservePaths := false;
- xZip.ProcessSubfolders := false;
- xZip.SkipIfExisting := false;
- xZip.SkipIfNotExisting := false;
- xZip.SkipIfOlderDate := false;
- xZip.SkipIfOlderVersion := false;
- xZip.TempFolder := ''; { Empty means default Windows temp folder }
- xZip.UseTempFile := true;
- xZip.UnzipToFolder := '';
- xZip.ZipFilename := '';
- xZip.SpanMultipleDisks := xdsRemovableDrivesOnly;
- xZip.ExtraHeaders := 0;
-
- { General SFX stuff }
- xZip.SfxBinaryModule := '';
- xZip.SfxResetButtons;
- xZip.SfxResetMessages;
- xZip.SfxResetStrings;
- end;
-
- { Fill a list with Xceed attributes. Uses the Object field as a holder for
- Xceed xcdFileAttributes enumeration values }
- procedure XceedFillAttributeList( var lstAttributes : TCheckListBox );
- begin
- lstAttributes.Items.Clear;
- lstAttributes.Items.AddObject( 'Archive', TObject( xfaArchive ) );
- lstAttributes.Items.AddObject( 'Read-only', TObject( xfaReadOnly ) );
- lstAttributes.Items.AddObject( 'Hidden', TObject( xfaHidden ) );
- lstAttributes.Items.AddObject( 'System', TObject( xfaSystem ) );
- lstAttributes.Items.AddObject( 'Volume label', TObject( xfaVolume ) );
- lstAttributes.Items.AddObject( 'Folder', TObject( xfaFolder ) );
- lstAttributes.Items.AddObject( 'Compressed', TObject( xfaCompressed ) );
- end;
-
- { Return Xceed attributes value for selected items. Use with XceedFillAttributeList }
- function XceedGetSelectedAttributes( var lstAttributes : TCheckListBox ) : integer;
- var
- i : integer;
- nAttributes : integer;
- begin
- nAttributes := xfaNone;
-
- for i := 0 to lstAttributes.Items.Count-1 do
- begin
- if lstAttributes.Checked[i] then
- nAttributes := nAttributes + integer( lstAttributes.Items.Objects[i] );
- end;
-
- result := nAttributes;
- end;
-
- { Set the attributes found in the given attribute mask }
- procedure XceedSetSelectedAttributes( var lstAttributes : TCheckListBox;
- xAttrib : xcdFileAttributes );
- var
- i : integer;
- xOne : xcdFileAttributes;
- begin
- for i := 0 to lstAttributes.Items.Count-1 do
- begin
- xOne := xcdFileAttributes( lstAttributes.Items.Objects[i] );
- lstAttributes.Checked[i] := ( ( xOne and xAttrib ) = xOne );
- end;
- end;
-
- {-----------------------------------------------------------------------------}
- { Form's methods }
- {-----------------------------------------------------------------------------}
-
- { Update hints with linefeeds for better output }
- procedure TfrmMain.UpdateFieldHints;
- begin
- { Previewing }
- edtPFilesToProcess.Hint := cFilesToProcessHint;
- edtPFilesToExclude.Hint := cFilesToExcludeHint;
- chkPProcessSubfolders.Hint := cProcessSubfoldersHint;
- lstPRequiredFileAttributes.Hint := cRequiredFileAttributesHint;
- lstPExcludedFileAttributes.Hint := cExcludedFileAttributesHint;
- btPreviewFiles.Hint := cPreviewFilesHint;
-
- { Zipping }
- edtZZipFilename.Hint := cZipFilenameHint;
- edtZBasePath.Hint := cBasePathHint;
- edtZFilesToProcess.Hint := cFilesToProcessHint;
- edtZFilesToExclude.Hint := cFilesToExcludeHint;
- chkZProcessSubfolders.Hint := cProcessSubfoldersHint;
- chkZPreservePaths.Hint := cPreservePathsHint;
- chkZUseTempFile.Hint := cUseTempFileHint;
- edtZTempFolder.Hint := cTempFolderHint;
- btZip.Hint := cZipHint;
-
- { Listing }
- edtLZipFilename.Hint := cZipFilenameHint;
- dtLMinDateToProcess.Hint := cMinDateToProcessHint;
- dtLMaxDateToProcess.Hint := cMaxDateToProcessHint;
- edtLMinSizeToProcess.Hint := cMinSizeToProcessHint;
- edtLMaxSizeToProcess.Hint := cMaxSizeToProcessHint;
- btList.Hint := cListZipContentsHint;
-
- { Unzipping }
- edtUZipFilename.Hint := cZipFilenameHint;
- edtUUnzipToFolder.Hint := cUnzipToFolderHint;
- edtUFilesToProcess.Hint := cFilesToProcessHint;
- edtUFilesToExclude.Hint := cFilesToExcludeHint;
- chkUSkipIfExisting.Hint := cSkipIfExistingHint;
- chkUSkipIfNotExisting.Hint := cSkipIfNotExistingHint;
- chkUSkipIfOlderDate.Hint := cSkipIfOlderDateHint;
- chkUSkipIfOlderVersion.Hint := cSkipIfOlderVersionHint;
- btUnzip.Hint := cUnzipHint;
-
- { Zipping Sfx }
- edtSZipFilename.Hint := cZipFilenameSfxHint;
- edtSFilesToProcess.Hint := cFilesToProcessHint;
- edtSSfxBinaryModule.Hint := cSfxBinaryModuleHint;
- edtSTitle.Hint := cSfxStringsHint;
- edtSIntro.Hint := cSfxMessagesHint;
- btZipSfx.Hint := cZipSfxHint;
- end;
-
- procedure TfrmMain.FormCreate(Sender: TObject);
- begin
- { We update hints for better look. We cannot put linefeeds in property editor! }
- UpdateFieldHints;
-
- { We fill attribute lists }
- XceedFillAttributeList( lstPRequiredFileAttributes );
- XceedFillAttributeList( lstPExcludedFileAttributes );
-
- { We set their initial state }
- XceedSetSelectedAttributes( lstPRequiredFileAttributes,
- xZip.RequiredFileAttributes );
- XceedSetSelectedAttributes( lstPExcludedFileAttributes,
- xZip.ExcludedFileAttributes );
- end;
-
- {-----------------------------------------------------------------------------}
- { Examples of how to use XceedZip }
- {-----------------------------------------------------------------------------}
-
- { PreviewFiles example:
- This method let's you list all files (through the "OnPreviewingFile" event)
- that would be processed by the Zip method with the same property values. }
- procedure TfrmMain.btPreviewFilesClick(Sender: TObject);
- var
- xErr : xcdError;
- begin
- { To be sure other tabs settings do not interfere with this example, we
- start by resetting XceedZip properties to default values }
- XceedResetDefaultProperties( xZip );
-
- { Clear the result list before starting }
- edtResults.Clear;
- edtResults.Lines.Add( 'PreviewFiles example:' );
-
- { Set properties displayed on this tab }
- xZip.FilesToProcess := edtPFilesToProcess.Text; { required }
- xZip.FilesToExclude := edtPFilesToExclude.Text;
- xZip.ProcessSubfolders := chkPProcessSubfolders.Checked;
- xZip.RequiredFileAttributes := XceedGetSelectedAttributes( lstPRequiredFileAttributes );
- xZip.ExcludedFileAttributes := XceedGetSelectedAttributes( lstPExcludedFileAttributes );
-
- { Launch the previewing }
- xErr := xZip.PreviewFiles( false );
- end;
-
- { Zip method:
- The files that are matched by the filtering properties will be added to the
- zip file specified by the ZipFilename property. }
- procedure TfrmMain.btZipClick(Sender: TObject);
- var
- xErr : xcdError;
- begin
- { To be sure other tabs settings do not interfere with this example, we
- start by resetting XceedZip properties to default values }
- XceedResetDefaultProperties( xZip );
-
- { Clear the result list before starting }
- edtResults.Lines.Clear;
- edtResults.Lines.Add( 'Zip example:' );
-
- { Set properties displayed on this tab }
- xZip.ZipFilename := edtZZipFilename.Text; { required }
- xZip.BasePath := edtZBasePath.Text;
- xZip.FilesToProcess := edtZFilesToProcess.Text; { required }
- xZip.FilesToExclude := edtZFilesToExclude.Text;
- xZip.ProcessSubfolders := chkZProcessSubfolders.Checked;
- xZip.PreservePaths := chkZPreservePaths.Checked;
- xZip.UseTempFile := chkZUseTempFile.Checked;
- xZip.TempFolder := edtZTempFolder.Text;
-
- { Launch the zipping }
- xErr := xZip.Zip;
- end;
-
- { ListZipContents method:
- Lists (through the OnListingFile event) the files contained in the zip file
- specified by the ZipFilename property. You can set the filtering propeties
- to list only particular files, or leave the FilesToProcess empty to list
- everything. }
- procedure TfrmMain.btListClick(Sender: TObject);
- var
- xErr : xcdError;
- begin
- { To be sure other tabs settings do not interfere with this example, we
- start by resetting XceedZip properties to default values }
- XceedResetDefaultProperties( xZip );
-
- { Clear the result list before starting }
- edtResults.Lines.Clear;
- edtResults.Lines.Add( 'ListZipContents example:' );
-
- { Set properties displayed on this tab }
- xZip.ZipFilename := edtLZipFilename.Text; { required }
- xZip.MinDateToProcess := dtLMinDateToProcess.Date;
- xZip.MaxDateToProcess := dtLMaxDateToProcess.Date;
- xZip.MinSizeToProcess := StrToIntDef( edtLMinSizeToProcess.Text, 0 );
- xZip.MaxSizeToProcess := StrToIntDef( edtLMaxSizeToProcess.Text, 0 );
-
- { Launch the listing }
- xErr := xZip.ListZipContents;
- end;
-
- { Unzip method:
- Unzips from the specified zip file (ZipFilename property) files that match
- the filtering properties. }
- procedure TfrmMain.btUnzipClick(Sender: TObject);
- var
- xErr : xcdError;
- begin
- { To be sure other tabs settings do not interfere with this example, we
- start by resetting XceedZip properties to default values }
- XceedResetDefaultProperties( xZip );
-
- { Clear the result list before starting }
- edtResults.Lines.Clear;
- edtResults.Lines.Add( 'Unzip example:' );
-
- { Set properties displayed on this tab }
- xZip.ZipFilename := edtUZipFilename.Text; { required }
- xZip.UnzipToFolder := edtUUnzipToFolder.Text; { required }
- xZip.FilesToProcess := edtUFilesToProcess.Text; { required }
- xZip.FilesToExclude := edtUFilesToExclude.Text;
- xZip.SkipIfExisting := chkUSkipIfExisting.Checked;
- xZip.SkipIfNotExisting := chkUSkipIfNotExisting.Checked;
- xZip.SkipIfOlderDate := chkUSkipIfOlderDate.Checked;
- xZip.SkipIfOlderVersion := chkUSkipIfOlderVersion.Checked;
-
- { Launch the unzipping }
- xErr := xZip.Unzip;
- end;
-
- { Zip method:
- When SfxBinaryModule contains a filename, then the resulting zip file is a
- self-extracting zip file that uses this binary module as a binary header.
- But appart from that (and changing the Sfx options with the Sfx properties),
- creating a self-extracting zip file is just like creating a normal zip file. }
- procedure TfrmMain.btZipSfxClick(Sender: TObject);
- var
- xErr : xcdError;
- begin
- { To be sure other tabs settings do not interfere with this example, we
- start by resetting XceedZip properties to default values }
- XceedResetDefaultProperties( xZip );
-
- { Clear the result list before starting }
- edtResults.Lines.Clear;
- edtResults.Lines.Add( 'Zip Sfx example:' );
-
- { Set properties displayed on this tab }
- xZip.ZipFilename := edtSZipFilename.Text; { required }
- xZip.FilesToProcess := edtSFilesToProcess.Text; { required }
- xZip.SfxBinaryModule := edtSSfxBinaryModule.Text; { required to make an EXE }
- xZip.SfxStrings[ xssTitle ] := edtSTitle.Text;
- xZip.SfxMessages[ xsmIntro ] := edtSIntro.Text;
-
- { Launch the zipping }
- xErr := xZip.Zip;
- end;
-
- {-----------------------------------------------------------------------------}
- { XceedZip events handling examples }
- {-----------------------------------------------------------------------------}
-
- { OnFileStatus event:
- Triggered during processing of a file, at every 32k. Gives a status on each
- file, one at a time, while it is being processed. Perfect for a file by file
- progress bar. You can use the CurrentOperation property to recall what this
- XceedZip instance is doing and display a proper status message. }
- procedure TfrmMain.xZipFileStatus(Sender: TObject;
- const sFilename: WideString; lSize, lCompressedSize,
- lBytesProcessed: Integer; nBytesPercent, nCompressionRatio: Smallint;
- bFileCompleted: WordBool);
- begin
- if lBytesProcessed = 0 then
- begin
- case TXceedZip( Sender ).CurrentOperation of
- xcoZipping:
- edtResults.Lines.Add( 'Zipping ' + sFilename );
- xcoUnzipping:
- edtResults.Lines.Add( 'Zipping ' + sFilename );
- end;
- end;
- end;
-
- { OnGlobalStatus event:
- Triggered during processing of files, at every 32k. Gives general status of
- the complete process. Perfect for a general progress bar. }
- procedure TfrmMain.xZipGlobalStatus(Sender: TObject; lFilesTotal,
- lFilesProcessed, lFilesSkipped: Integer; nFilesPercent: Smallint;
- lBytesTotal, lBytesProcessed, lBytesSkipped: Integer;
- nBytesPercent: Smallint; lBytesOutput: Integer;
- nCompressionRatio: Smallint);
- begin
- barGlobal.Position := nBytesPercent;
- end;
-
- { OnInsertDisk event:
- Triggered when processing a spanned zip file, or when creating a spanned zip
- file and the current disk is filled. When nDiskNumber is zero, it means the
- last disk of the set is required, in order to read the zip file's list of
- files. }
- procedure TfrmMain.xZipInsertDisk(Sender: TObject; nDiskNumber: Integer;
- var bDiskInserted: WordBool);
- var
- nAnswer : Word;
- begin
- { When nDiskNumber is 0, this means the last disk of the set is required }
- if nDiskNumber = 0 then
- nAnswer := MessageDlg( 'This file is part of a multidisk zip file. Please ' +
- 'insert the last disk of the set.', mtInformation,
- [mbOK,mbCancel], 0 )
- else
- nAnswer := MessageDlg( 'Please insert disk #' + IntToStr( nDiskNumber ) + '.',
- mtInformation, [mbOK,mbCancel], 0 );
-
- if nAnswer = mrOK then
- bDiskInserted := true;
- end;
-
- { OnListingFile event:
- Triggered while listing the contents of a zip file with the ListZipContents
- method. }
- procedure TfrmMain.xZipListingFile(Sender: TObject; const sFilename,
- sComment: WideString; lSize, lCompressedSize: Integer;
- nCompressionRatio: Smallint; xAttributes: TOleEnum; lCRC: Integer;
- dtLastModified, dtLastAccessed, dtCreated: TDateTime; xMethod: TOleEnum;
- bEncrypted: WordBool; lDiskNumber: Integer; bExcluded: WordBool;
- xReason: TOleEnum);
- begin
- if bExcluded then
- edtResults.Lines.Add( 'Excluding ' + sFilename + ' (reason: ' + IntToStr( xReason ) + ')' )
- else
- edtResults.Lines.Add( 'Including ' + sFilename );
- end;
-
- { OnPreviewingFile event:
- Triggered when previewing files on disk with the PreviewFiles method. }
- procedure TfrmMain.xZipPreviewingFile(Sender: TObject; const sFilename,
- sSourceFilename: WideString; lSize: Integer; xAttributes: TOleEnum;
- dtLastModified, dtLastAccessed, dtCreated: TDateTime;
- bExcluded: WordBool; xReason: TOleEnum);
- begin
- if bExcluded then
- edtResults.Lines.Add( 'Excluding ' + sFilename + ' (reason: ' + IntToStr( xReason ) + ')' )
- else
- edtResults.Lines.Add( 'Including ' + sFilename );
- end;
-
- { OnProcessCompleted event:
- Triggered when any process submitted terminates. It is highly useful when
- processing files with BackgroundProcessing set to true. This is how you
- know the process completed! }
- procedure TfrmMain.xZipProcessCompleted(Sender: TObject; lFilesTotal,
- lFilesProcessed, lFilesSkipped, lBytesTotal, lBytesProcessed,
- lBytesSkipped, lBytesOutput: Integer; nCompressionRatio: Smallint;
- xResult: TOleEnum);
- begin
- { Display the error number and default message }
- edtResults.Lines.Add( 'Process completed with error code ' + IntToStr( xResult ) );
- edtResults.Lines.Add( '-=> ' + TXceedZip( Sender ).GetErrorDescription( xvtError, xResult ) );
-
- { Display statistics }
- case TXceedZip( Sender ).CurrentOperation of
- xcoZipping, xcoUnzipping, xcoRemoving:
- begin
- edtResults.Lines.Add( IntToStr( lFilesProcessed ) + ' file(s) processed for ' +
- IntToStr( lBytesProcessed ) + ' bytes' );
- edtResults.Lines.Add( IntToStr( lFilesSkipped ) + ' file(s) skipped for ' +
- IntToStr( lBytesSkipped ) + ' bytes' );
- end;
- xcoListing:
- edtResults.Lines.Add( IntToStr( lFilesTotal ) + ' file(s) listed' );
- xcoPreviewing:
- edtResults.Lines.Add( IntToStr( lFilesTotal ) + ' file(s) previewed' );
- end;
- end;
-
- { OnReplacingFile event:
- Triggered while zipping or unzipping, when a file is about to be replaced.
- The default value of the bReplaceFile parameter is true, so you do not need
- to implement anything if you always want to replace files. }
- procedure TfrmMain.xZipReplacingFile(Sender: TObject; const sFilename,
- sComment: WideString; lSize: Integer; xAttributes: TOleEnum;
- dtLastModified, dtLastAccessed, dtCreated: TDateTime;
- const sOrigFilename: WideString; lOrigSize: Integer;
- xOrigAttributes: TOleEnum; dtOrigLastModified, dtOrigLastAccessed,
- dtOrigCreated: TDateTime; var bReplaceFile: WordBool);
- begin
- { We'll stick to the default behavior of replacing everything ! }
- end;
-
- { OnSkippingFile event:
- Triggered during any processing, when a file is excluded because of the
- filtering properties (0 < xReason < 100), or because an error prevented this
- file from being processed (xReason >= 100). }
- procedure TfrmMain.xZipSkippingFile(Sender: TObject; const sFilename,
- sComment, sFilenameOnDisk: WideString; lSize, lCompressedSize: Integer;
- xAttributes: TOleEnum; lCRC: Integer; dtLastModified, dtLastAccessed,
- dtCreated: TDateTime; xMethod: TOleEnum; bEncrypted: WordBool;
- xReason: TOleEnum);
- begin
- edtResults.Lines.Add( 'Skipping ' + sFilename + ' (reason: ' + IntToStr( xReason ) + ')' );
- end;
-
- { OnWarning event:
- Triggered during processing when a recoverable error is encountered. }
- procedure TfrmMain.xZipWarning(Sender: TObject;
- const sFilename: WideString; xWarning: TOleEnum);
- begin
- edtResults.Lines.Add( 'Warnign ' + IntToStr( xWarning ) );
- end;
-
- { OnZipContentsStatus event:
- Triggered while reading the contents of an existing zip file. This happens
- when unzipping, adding files to an existing zip file, removing files,
- testing a zip file, converting a zip file, or getting the zip file's info.
- This event is useful when dealing with very large zip files, and you want
- to display a progress status while the zip file is read. }
- procedure TfrmMain.xZipZipContentsStatus(Sender: TObject; lFilesRead,
- lFilesTotal: Integer; nFilesPercent: Smallint);
- begin
- { We're not doing anything special here! }
- end;
-
- end.
-
-